package com.golf.assembly.war.servlet;

import golf.stockdata.framework.ability.BatchAbility;
import golf.stockdata.framework.spring.ApplicationObjectContainer;
import golf.stockdata.framework.spring.ApplicationServiceProcessor;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;


/**
 * Servlet implementation class BatchStartupServlet
 */
public class BatchStartupServlet extends HttpServlet {


    /**
	 * 
	 */
	private static final long serialVersionUID = 4299435486310017330L;
	
	private static Logger logger = Logger.getLogger(BatchStartupServlet.class);
	
	private BatchAbility batchAbility;

	/**
     * Default constructor. 
     */
	public BatchStartupServlet() {

		logger.info("Initializing BatchStartupServlet");
		logger.debug(">>> BatchStartupServlet");
		logger.debug("Initializing Spring Context");
		
		ApplicationObjectContainer aoc = ApplicationServiceProcessor.getAOC();
		batchAbility = (BatchAbility) aoc.getAbility("golf.stockdata.framework.batch.BatchAbility");
		
		logger.debug("Starting up BatchAbility");
		batchAbility.start();
		aoc.release();
		logger.debug("<<< BatchStartupServlet");
		
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	
	public void destroy(){
		logger.debug(">>> destroy");
		batchAbility.destroy();
		logger.debug("<<< destroy");
		super.destroy();
	}

}
